package com.example.figurehecheng.controller.merchant;


import com.example.figurehecheng.common.result.PageResult;
import com.example.figurehecheng.common.result.Result;
import com.example.figurehecheng.domain.dto.ProgramDTO;
import com.example.figurehecheng.domain.dto.ProgramPageDTO;
import com.example.figurehecheng.domain.dto.SaveHouseDTO;
import com.example.figurehecheng.service.IProgramService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 宇科工作室
 * @since 2024-10-18
 */
@RestController("merchantProgramController")
@RequestMapping("/merchant/program")
@CrossOrigin
@RequiredArgsConstructor
@Api(tags = "项目管理相关接口")
@Slf4j
public class ProgramController {

    private final IProgramService programService;

    /**
     * 分页查询项目信息
     * @param programPageDTO
     * @return
     */
    @GetMapping("/selectProgramPage")
    @ApiOperation("分页查询项目信息")
    public Result<PageResult> selectProgramPage(ProgramPageDTO programPageDTO){
        log.info("分页查询项目信息：{}", programPageDTO);
        PageResult pageResult = programService.selectProgramPage(programPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 添加项目信息
     * @param programDTO
     * @return
     */
    @PostMapping("/saveProgram")
    @ApiOperation("添加项目信息")
    public Result saveProgram(@RequestBody ProgramDTO programDTO){
        log.info("添加项目信息：{}", programDTO);
        programService.saveHouse(programDTO);
        return Result.success();
    }

    /**
     * 修改项目
     * @param programDTO
     * @return
     */
    @PostMapping("/updateProgram")
    @ApiOperation("修改项目")
    public Result updateProgram(@RequestBody ProgramDTO programDTO){
        log.info("修改项目：{}", programDTO);
        programService.updateProgram(programDTO);
        return Result.success();
    }

    /**
     * 根据id删除项目
     * @param id
     * @return
     */
    @DeleteMapping("/deleteProgram")
    @ApiOperation("根据id删除项目")
    public Result deleteProgram(@RequestBody Integer id){
        log.info("根据id删除项目：{}", id);
        programService.deleteProgram(id);
        return Result.success();
    }

}
